<template>
  <div class="floorBox-wrap">
    <div class="v-modal" style="z-index: 99;" @click="handleMantle"></div>
    <!-- 楼层弹框 -->
    <div class="floorBox">
      <div
        target="_blank"
        class="item"
        :class="{
          grayActive: item.type == 2,
          redActive: isFloorSelect(item)
        }"
        v-for="item in floorList"
        :key="item.number"
        @click="handleToUrl(item)"
      >
        <b>{{ item.number }}F</b>
        <span>{{ item.title }}</span>
      </div>
    </div>
  </div>
</template>

<script>
import api from "servicePath/index";
import { mapState } from "vuex";

export default {
  data() {
    return {
      floorList: [] // 楼层
    };
  },
  created() {
    this.handleGetFloorList();
  },
  computed: {
    ...mapState(["lang", "userInfo"])
  },
  methods: {
    isFloorSelect(item) {
      var isfoundation = this.$route.path.indexOf("foundation") != -1;
      var isfakuma = this.$route.path.indexOf("fakuma") != -1;

      console.log(this.$route.fullPath);
      var isFloorOne = this.$route.fullPath.indexOf("scene?floor=1") != -1;
      var isFloorTwo = this.$route.fullPath.indexOf("scene?floor=2") != -1;

      if (
        this.$route.fullPath.indexOf("foundation/wap/scene") != -1 &&
        !isFloorTwo
      ) {
        isFloorOne = true;
      }

      if (isfoundation) {
        if (item.number == 1 && isFloorOne) {
          return true;
        } else if (item.number == 2 && isFloorTwo) {
          return true;
        }
        // console.log("isfoundation", item.number, isFloorOne);

        return false;
      } else if (isfakuma) {
        if (item.number == 4) {
          return true;
        }
        return false;
      }
      return false;
    },
    // 楼层跳转
    handleToUrl(record) {
      if (record.type == 1) {
        if (record.number == 1) {
          this.$router.push("/foundation/wap/home?floor=1.2");
        } else if (record.number == 2) {
          this.$router.push("/foundation/wap/home?floor=2.1");
        } else if (record.number == 4) {
          this.$router.push("/fakuma/wap/home");
        }
      } else if (record.url.length > 0 && record.url != "正在建设") {
        window.open(record.url, "_blank");
      }
      this.handleMantle();
    },
    handleMantle(data) {
      this.$emit("handleMantle", data);
    },
    // 获取楼层
    async handleGetFloorList() {
      const params = {
        language: this.lang
      };
      const res = await api.getFloorList(params);
      this.mantle = true;
      this.floorList = res.data;
    }
  }
};
</script>

<style lang="scss" scoped>
.floorBox-wrap {
  .floorBox {
    position: absolute;
    top: 15%;
    left: 10%;
    right: 10%;
    z-index: 100;
    .item {
      display: inline-block;
      width: 100%;
      height: 60px;
      background: #fff;
      margin-top: 20px;
      border-radius: 8px;
      padding: 0 20px;
      b {
        display: inline-block;
        width: 35px;
        height: 35px;
        border-radius: 50%;
        color: #ff7f41;
        border: 2px solid;
        text-align: center;
        line-height: 32px;
        margin-top: 12px;
        margin-right: 10px;
      }
      span {
        font-size: 16px;
      }
    }
  }
  .grayActive {
    opacity: 0.5 !important;
  }
  .redActive {
    background: linear-gradient(to right, #ff7f41, #e6007e) !important;
    b {
      color: #fff !important;
    }
    span {
      color: #fff;
    }
  }
}
</style>
